package com.zenithmind.article.feign;

import com.zenithmind.article.pojo.vo.UserVO;
import com.zenithmind.common.result.Result;
import com.zenithmind.common.result.ResultCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 用户服务远程调用接口
 */
@FeignClient(name = "user-service", path = "/api/zenithMind/user", fallback = UserFeignClient.UserFeignFallback.class)
public interface UserFeignClient {
    
    /**
     * 根据ID获取用户信息
     */
    @GetMapping("/getUserById")
    Result<UserVO> getUserById(@RequestParam("userId") String id);

    /**
     * Fallback implementation for UserFeignClient.
     */
    @Slf4j
    class UserFeignFallback implements UserFeignClient {
        @Override
        public Result<UserVO> getUserById(String id) {
            log.error("UserFeignClient fallback: getUserById called for id {}. Returning error result.", id);
            // Return an error Result or a default UserVO within a success Result
            // Example: Returning error Result
            return Result.fail(ResultCode.SERVICE_UNAVAILABLE); 
            // Example: Returning default UserVO (if suitable)
            // UserVO defaultUser = new UserVO();
            // defaultUser.setId(id);
            // defaultUser.setUsername("Unknown User");
            // return Result.success(defaultUser);
        }
    }
} 